﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace BookManagementWpfApplication
{
    public class PageSwitcher : EventArgs
    {
        public bool Result { get; set; }
    }

    public static class PageSwitch
    {
        public static MainWindow mainWindow;

        public static EventHandler<PageSwitcher> PageChanging;
        public static EventHandler<PageSwitcher> PageChanged;

        public static void Switch(UserControl newPage)
        {
            var eventArgs = new PageSwitcher { Result = true };

            if (PageChanging != null)
                PageChanging.Invoke(mainWindow.Content.Children[0], eventArgs);

            if (!eventArgs.Result)
                return;

            mainWindow.Content.Children.Clear();
            mainWindow.Content.Children.Add(newPage);

            if (PageChanged != null)
                PageChanged.Invoke(mainWindow, null);
        }
    }
}
